﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using InstantNaukriDAL;
using System.Collections.Generic;
using System.IO;

public partial class PostResume : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            FillCity();
            FuntionalArea();
            Filleducation();
            FillIndustry();
            FillddlExperience();
        }
    }

    private void FillCity()
    {
        try
        {
            clsCity objclsCity = new clsCity();
            List<IN_TB_CITY> objIN_TB_CITY = new List<IN_TB_CITY>();
            objIN_TB_CITY = objclsCity.GetAllCities();
            ddlLocation.Items.Clear();
            ddlLocation.AppendDataBoundItems = true;
            ddlLocation.DataTextField = "CITY";
            ddlLocation.DataValueField = "ID";
            ddlLocation.Items.Add("Select");
            ddlLocation.Items[0].Value = "0";
            ddlLocation.DataSource = objIN_TB_CITY;
            ddlLocation.DataBind();
        }
        catch (Exception)
        {

            throw;
        }
    }
    private void Filleducation()
    {
        try
        {
            clsEducationDAL objclsEducationDAL = new clsEducationDAL();
            List<IN_TB_EDUCATION> objIN_TB_EDUCATION = new List<IN_TB_EDUCATION>();
            objIN_TB_EDUCATION = objclsEducationDAL.GetAllEducationDegree();
            ddlBasicGraduation.Items.Clear();
            ddlBasicGraduation.AppendDataBoundItems = true;
            ddlBasicGraduation.DataTextField = "DEGREE";
            ddlBasicGraduation.DataValueField = "ID";
            ddlBasicGraduation.Items.Add("Select");
            ddlBasicGraduation.Items[0].Value = "0";
            ddlBasicGraduation.DataSource = objIN_TB_EDUCATION;
            ddlBasicGraduation.DataBind();
        }
        catch (Exception)
        {

            throw;
        }
    }
    protected void FillddlExperience()
    {
        try
        {
            //Min Experience Required
            ddlexperience.Items.Clear();
            ddlexperience.AppendDataBoundItems = true;
            ddlexperience.Items.Add("Select");
            ddlexperience.Items[0].Value = "0";
            for (int i = 1; i <= 70; i++)
            {
                ddlexperience.Items.Add(i.ToString());
                ddlexperience.Items[i].Value = i.ToString();
            }
            ddlexperience.DataBind();
        }
        catch (Exception)
        {

            throw;
        }
    }

    private void FillIndustry()
    {
        try
        {
            clsIndustriesDAL objclsIndustriesDAL = new clsIndustriesDAL();
            List<IN_TB_INDUSTRY> objIN_TB_INDUSTRY = new List<IN_TB_INDUSTRY>();
            objIN_TB_INDUSTRY = objclsIndustriesDAL.GetAllIndustries();
            ddlCurrentIndustry.Items.Clear();
            ddlCurrentIndustry.AppendDataBoundItems = true;
            ddlCurrentIndustry.DataTextField = "INDUSTRY";
            ddlCurrentIndustry.DataValueField = "ID";
            ddlCurrentIndustry.Items.Add("Select");
            ddlCurrentIndustry.Items[0].Value = "0";
            ddlCurrentIndustry.DataSource = objIN_TB_INDUSTRY;
            ddlCurrentIndustry.DataBind();
        }
        catch (Exception)
        {

            throw;
        }
    }
    private void FuntionalArea()
    {
        try
        {
            clsFunctionalAreaDAL objclsFunctionalAreaDAL = new clsFunctionalAreaDAL();
            List<IN_TB_FUNCTIONAL_AREA> objIN_TB_FUNCTIONAL_AREA = new List<IN_TB_FUNCTIONAL_AREA>();
            objIN_TB_FUNCTIONAL_AREA = objclsFunctionalAreaDAL.GetAllFunctionalAreas();
            ddlFunctionalArea.Items.Clear();
            ddlFunctionalArea.AppendDataBoundItems = true;
            ddlFunctionalArea.DataTextField = "FUNCTIONAL_AREA";
            ddlFunctionalArea.DataValueField = "ID";
            ddlFunctionalArea.Items.Add("Select");
            ddlFunctionalArea.Items[0].Value = "0";
            ddlFunctionalArea.DataSource = objIN_TB_FUNCTIONAL_AREA;
            ddlFunctionalArea.DataBind();
        }
        catch (Exception)
        {

            throw;
        }
    }

    protected void btnRegister_Click(object sender, EventArgs e)
    {
        try
        {


            clsUserLoginDAL objclsUserLoginDAL = new clsUserLoginDAL();
            //Saving User
            IN_TB_USER objIN_TB_USER = new IN_TB_USER();
            objIN_TB_USER.EMAIL = txtemail.Text;
            if (rbtnLoginId.SelectedValue == "1")
            {
                objIN_TB_USER.LOGIN_ID = txtemail.Text;
                objIN_TB_USER.PASSWORD = txtPassword.Text;
            }
            if (rbtnLoginId.SelectedValue == "2")
            {
                objIN_TB_USER.LOGIN_ID = txtmobile.Text;
                objIN_TB_USER.PASSWORD = txtPassword.Text;
            }
            objIN_TB_USER.NAME = txtname.Text;
            objIN_TB_USER.MOBILE = txtmobile.Text;
            objIN_TB_USER.EMAIL = txtemail.Text;
            objIN_TB_USER.STATUS = 1;
            objIN_TB_USER.ROLEID = 4;
            objIN_TB_USER.DOB = Convert.ToDateTime(txtDOB.Text);
            objIN_TB_USER.CREATED_BY = 1;
            int UserId = objclsUserLoginDAL.SaveUser(objIN_TB_USER);

            // Saving User Profile
            clsProfileDAL objclsProfileDAL = new clsProfileDAL();
            IN_TB_PROFILE objIN_TB_PROFILE = new IN_TB_PROFILE();
            objIN_TB_PROFILE.F_NAME = txtname.Text;
            objIN_TB_PROFILE.DOB = Convert.ToDateTime(txtDOB.Text);
            objIN_TB_PROFILE.EMAIL = txtemail.Text;
            objIN_TB_PROFILE.MOBILE = txtmobile.Text; ;
            objIN_TB_PROFILE.PHONE = txtmobile.Text;
            objIN_TB_PROFILE.USER_ID = UserId;
            int profieleid = objclsProfileDAL.SaveProfile(objIN_TB_PROFILE);

            // Saving User Resume
            string CVPath = Server.MapPath("~/Resumes/") + UserId.ToString();
            DirectoryInfo objFileInfo = new DirectoryInfo(CVPath);
            objFileInfo.Create();
            fuResume.SaveAs(CVPath + "/" + fuResume.FileName);
            clsResumeDAL objclsResumeDAL = new clsResumeDAL();
            IN_TB_RESUME_MST ibjIN_TB_RESUME_MST = new IN_TB_RESUME_MST();
            ibjIN_TB_RESUME_MST.KEY_SKILLS = txtKeySkills.Text;
            ibjIN_TB_RESUME_MST.RESUME_HEADLINE = txtResumeHeadline.Text;
            ibjIN_TB_RESUME_MST.CURRENT_LOCATION = Convert.ToInt32(ddlLocation.SelectedValue);
            ibjIN_TB_RESUME_MST.TOTAL_EXP = Convert.ToInt32(ddlexperience.SelectedValue);
            ibjIN_TB_RESUME_MST.FUNCTIONAL_AREA = Convert.ToInt32(ddlFunctionalArea.SelectedValue);
            ibjIN_TB_RESUME_MST.USER_ID = UserId;
            ibjIN_TB_RESUME_MST.RESUME_PATH = UserId.ToString() + "/" + fuResume.FileName;
            int resumeid = objclsResumeDAL.SaveResume(ibjIN_TB_RESUME_MST);
            string roleid = clsEncryptionDecryption.Encrypt("4");
            Session["UserId"] = UserId;
            if (Session["UserId"] != null)
                Response.Redirect("JobseekerProfile.aspx?roleid=" + roleid);
        }
        catch (Exception)
        {

            throw;
        }
    }


    protected void imgDob_Click(object sender, ImageClickEventArgs e)
    {
        //try
        //{
        //    clDob.Visible = true;
        //}
        //catch (Exception)
        //{

        //    throw;
        //}
    }
    protected void clDob_SelectionChanged(object sender, EventArgs e)
    {
        //try
        //{
        //    txtDOB.Text = clDob.SelectedDate.ToString("dd-MMM-yyyy");
        //    clDob.Visible = false;
        //}
        //catch (Exception)
        //{

        //    throw;
        //}

    }
}
